<?php include('header.php'); ?>

<!-- additional javascript hear -->

<style type="text/css">
<!--
#wrapper #one_wide .item table tr td a img {
	color: #F2F9FF;
}

.date {
	color: #B0B7C8;
}
-->
</style>
</head>
<body>
<div id="wrapper">
<!-- menu -->
<?php include('menu.php'); ?>
<!-- end menu -->

<!-- navigator -->
<?php include('navigator.php'); ?>
<!-- nav end -->

 <div id="oneLeft">
<?php
	if($this->session->flashdata('error'))
	{ 
		echo '<div class="error">' . $this->session->flashdata('error') . '</div>';
	}
	elseif($this->session->flashdata('success'))
	{
		echo '<div class="success">' . $this->session->flashdata('success') . '</div>';
	}
	
	echo validation_errors('<div class="error">', '</div>');
?>

<div class="item">


<?php
if($blog == false){
	echo "คุณยังไม่ได้สร้างบล็อก &nbsp;";
	echo anchor('profile/blog_create', 'คลิ๊กที่นี่เพื่อเขียนบทความแรกของคุณ!');
}else {
	foreach($blog as $row):
	$blogID = $row['blog_id'];
	$this->blogmodel->blogCount($row['blog_id']);
?>
<div class="blogtitle">
<h2><?=$row['blog_name'];?></h2>

<?php
//$url_title = url_title($row['blog_name']);
//echo $url_title;
?>

โพสต์เมื่อ: <?=$this->usermodel->relativeTime($row['blog_date']);?> | จำนวนผู้เยี่ยมชม: <?=$row['blog_view'];?>
</div>
<?=$row['blog_content'];?>
<?php endforeach;?>
<hr />

<?php 
echo form_open('blog/blog_comment');
$CI = &get_instance();
?>
<textarea class="commentbox" name="blog_comment"></textarea>
<input type="hidden" name="redirectURL" value="<?=$CI->uri->uri_string();?>">
<input type="hidden" name="blog_id" value="<?=$blogID;?>">
<input type="submit" class="buttoncomment" value="แสดงความคิดเห็น">
</form>
<div class='subitem'>
	<?php
	$comment = $this->blogmodel->getBlogComment($blogID, 10);
	if($comment == false){
		echo "<p><center>ยังไม่มีใครแสดงความคิดเห็น</center></p>";
	}else{
	foreach($comment as $comRow):
	?>
<table width="600" border="0" cellspacing="0" cellpadding="0" >
  <tr>
    <td width="32px" height="35px" rowspan="2" align="center">
	<a href="<?=base_url() . 'user/id/' . $comRow['ref_user_id'];?>"><img width="32px" height="35px" src="<?=$this->usermodel->getAvatar($comRow['ref_user_id']);?>"></a>
	</td>
    <td width="366" valign="top">
	<h4>
		<?=$this->usermodel->getName($comRow['ref_user_id']);?>
	</h4>
	</td>
  </tr>
  <tr>
    <td  width="32px" height="35" valign="top">
		<? echo $comRow['blog_comm_content'] . "<h6 class='date'>" .  $this->usermodel->relativeTime($comRow['blog_comm_date']) . "</h6>";?>
	</td>
  </tr>
</table>
	<?php
	endforeach;
	}
	?>
</div>
<?php } ?>
</div>
</div>
<div id="three">
	
	<div class="item">
	<h2><img src="<?=base_url();?>application/images/profile.png"  alt="Profile" /></h2>
	<table width="100%" border="0" cellpadding="0" cellspacing="2">
	  <tr>
	    <td width="3%" rowspan="8" align="left" valign="top"><img src="<?=$this->usermodel->getAvatar($blogOwner);?>"></td>
	    <td width="97%" valign="top" ><b><?=$this->usermodel->getName($blogOwner);?></b></td>
	    </tr>
	  <tr>
	    <td valign="top">สถานะ : <?=$this->usermodel->getAbout($blogOwner);?></td>
	    </tr>
	  </table>
	</div>
	
	<div class="item">
	<h2><img src="<?=base_url();?>application/images/last_blog.png"  alt="Last blog" /></h2>
	<p>
	<?php
	if($lastBlog == false){
		echo "ยังไม่เคยเขียนอะไรเลย!";
	}else {
	foreach($lastBlog as $lastBlogRow):
		{
			echo "<UL>";
			echo "<li>";
			echo anchor("blog/view/" . $lastBlogRow['blog_id'], $lastBlogRow['blog_name']);
			echo "</li>";
			echo "</UL>";
		}
	endforeach;
	}
	?>
	</p>
	</div>
	
	<div class="item">
	<h2><img src="<?=base_url();?>application/images/last_blog_comment.png"  alt="Last Comment" /></h2>
	<p>
		<?php
		if($lastComment == false) {
			echo "ไม่พบข้อมูล";
		}else{
		foreach($lastComment as $lstCommRow):
		{
			echo "<UL>";
			echo "<li>";
			echo anchor("blog/view/" . $lstCommRow['ref_blog_id'], $lstCommRow['blog_comm_content']);
			echo "</li>";
			echo "</UL>";
		}
		endforeach;
		}
		?>
	</p>
	</div>
</div>
<!-- footer -->
<?php include('footer.php');?>
<!-- footer end -->
</div>
</body>
</html>